import configparser
import os.path

import yaml

ini_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))),"config","conf.ini")
yaml_path= os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))),"data","data.yaml")
img_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))),'file','留言图片.PNG')

class FileRead:
    def __init__(self):
        self.ini_path = ini_path
        self.yaml_path = yaml_path
        self.img_path = img_path

    #读取ini格式文件内容
    def read_ini(self):
        conf = configparser.ConfigParser()
        conf.read(self.ini_path, encoding='utf-8')
        return conf

    #读取yaml内容
    def read_yaml(self):
        with open(self.yaml_path,"r",encoding="utf-8") as f:
            data=  yaml.load(f,Loader=yaml.FullLoader)
            return data

    #读取图片格式内容
    def read_img(self):
        file = open(self.img_path,"rb")
        return {"file" : ('留言图片.PNG',file,'image/png')}

    #写入yaml文件内容
    def write_yaml(self,data):
        with open(self.yaml_path,"a") as f:
            yaml.dump(data,f,encoding='utf-8',allow_unicode=True)

read = FileRead()
# print(yaml_path)